package com.k7k7.sserver.client;

import org.dom4j.Element;
import com.k7k7.sserver.room.RoomMgr;
import com.k7k7.client.BaseClient;

import java.util.Vector;

/**
 * User: Administrator
 * Date: 2009-4-27
 * Time: 15:29:57
 */
public class BroadCastOpt extends Opt{
	private ClientS client;

	public BroadCastOpt(ClientS client) {
		super();
		this.client = client;
	}

	/**
	 * 广播内容
	 *
	 * @param info
	 */
	protected void broadcast(Element info) {
		String target = info.attribute("target").getStringValue();
		if (target.equals("")) {
			return;
		}
		Element backe = (Element) info.clone();
		backe.remove(info.attribute("target"));
		backe.remove(info.attribute("users"));
		if (target.equals("4")) {
			RoomMgr.getInstance().sendToAllRoom(backe);
		} else {
			String uss = info.attributeValue("users");
			Vector<BaseClient> vus = new Vector<BaseClient>();
			if (!uss.equals("")) {
				String[] usss = uss.split("\\|");
				for (int i = 0; i < usss.length; i++) {
					ClientS uo = ClientMgrS.getInstance().getClientByID(Long.valueOf(usss[i]));
					if (null != uo) {
						uo.send(backe);
						vus.add(uo);
					}
				}
			}
			if (target.equals("2")) {
				this.client.roomOpt.room.sendToAllClients(backe);
			}
			if (target.equals("1")) {
			}
		}
	}
}
